﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities;
using VoxelConverter.VoxFormats;
using System.IO;

namespace VoxelConverter
{
    class Program
    {
        static void Main(string[] args)
        {
            Options options = new Options();
            CommandLineParser parser = new CommandLineParser(options);

            if (!parser.ParseCommandLine(args))
                return;

            if ((int)options.InputFormat <= 1)
            {
                Console.WriteLine("A Voxel format is required as input. Please select another format");
                return;
            }

            Console.WriteLine("Performing conversion, press any key to continue...");
            Console.ReadKey(true);

            // Load the Voxel Model
            // =====================
            VoxelModel model = null;
            switch (options.InputFormat)
            {
                case Format.Vox:
                    Console.WriteLine("Importing VOX file...");
                    model = MagicaVoxel.Load(options.InputFile);
                    break;
                default:
                    break;
            }

            switch (options.OutputFormat)
            {
                case Format.Obj:
                    Console.WriteLine("Exporting OBJ file...");
                    string fileContents = VoxelToObj.Convert(model);
                    File.WriteAllText(options.OutputFile, fileContents);
                    break;
                default:
                    break;
            }

            Console.WriteLine("...Finished...");
            Console.ReadKey(true);
        }
    }
}
